package net.hn.hnms.biz.emgcy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.hn.hnms.biz.emgcy.domain.AllocationRecordPo;
import net.hn.hnms.biz.emgcy.domain.dto.AllocationRecordDto;
import net.hn.hnms.biz.emgcy.domain.vo.AllocationRecordVo;
import net.hn.hnms.biz.emgcy.mapper.AllocationRecordMapper;
import net.hn.hnms.biz.emgcy.service.AllocationRecordService;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: baijiajun
 * @Date: 2022/9/13
 */
@Service
public class AllocationRecordServiceImpl extends ServiceImpl<AllocationRecordMapper, AllocationRecordPo> implements AllocationRecordService {
    @Autowired
    private AllocationRecordMapper allocationRecordMapper;

    @Override
    public ResponsePage<AllocationRecordVo> pageList(PageQuery pageQuery, AllocationRecordDto allocationRecordDto) {
        pageQuery.setPageNum(pageQuery.getPageNum() >= 1 ? (pageQuery.getPageNum() - 1) * pageQuery.getPageSize():0);
        List<AllocationRecordVo> list =  allocationRecordMapper.pageList(pageQuery.getPageSize(), pageQuery.getPageNum(), allocationRecordDto);
        if(list.isEmpty()){
            return new ResponsePage<>(new ArrayList(),0);
        }
        return new ResponsePage<>(list,list.get(0).getTotal());

    }

    @Override
    public Boolean update(AllocationRecordPo allocationRecordPo) {
        int update = allocationRecordMapper.updateById(allocationRecordPo);
        if(update>0){
            return true;
        }
        return false;    }

    @Override
    public Boolean delete(Long id) {
        int delete = allocationRecordMapper.deleteById(id);
        if(delete>0){
            return true;
        }
        return false;
    }

    @Override
    public Boolean add(AllocationRecordPo allocationRecordPo) {
        int insert = allocationRecordMapper.insert(allocationRecordPo);
        if(insert>0){
            return true;
        }
        return false;
    }
}
